# .\sqlacodegen --outfile ./model.py    mysql+pymysql://root:qiuwen123666@1.15.281.228:3306/ppp_project?db.CHARset=utf8mb8
from applications.extensions import db

from datetime import datetime

date_func = lambda in_date: in_date.strftime("%Y-%m-%d %H:%M:%S")


# class GenTable(db.Model):
#     __tablename__ = 'gen_table'
#     __table_args__ = {'comment': '代码生成业务表'}
#
#     table_id = db.Column(db.Integer(), primary_key=True, comment='编号')
#     table_name = db.Column(db.String(255), comment='表名称')
#     table_comment = db.Column(db.String(255), comment='表描述')
#     sub_table_name = db.Column(db.String(255), comment='关联子表的表名')
#     sub_table_fk_name = db.Column(db.String(255), comment='子表关联的外键名')
#     class_name = db.Column(db.String(128), comment='实体类名称')
#     tpl_category = db.Column(db.String(255), comment='使用的模板（crud单表操作 tree树表操作）')
#     package_name = db.Column(db.String(128), comment='生成包路径')
#     module_name = db.Column(db.String(30), comment='生成模块名')
#     business_name = db.Column(db.String(30), comment='生成业务名')
#     function_name = db.Column(db.String(68), comment='生成功能名')
#     function_author = db.Column(db.String(68), comment='生成功能作者')
#     gen_type = db.Column(db.CHAR(1), comment='生成代码方式（0zip压缩包 1自定义路径）')
#     gen_path = db.Column(db.String(255), comment='生成路径（不填默认项目路径）')
#     options = db.Column(db.String(1280), comment='其它生成选项')
#     create_by = db.Column(db.String(255), comment='创建者')
#     create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
#     update_by = db.Column(db.String(255), comment='更新者')
#     update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
#     remark = db.Column(db.String(255), comment='备注')
#
#
# class GenTableColumn(db.Model):
#     __tablename__ = 'gen_table_column'
#     __table_args__ = {'comment': '代码生成业务表字段'}
#
#     column_id = db.Column(db.Integer(), primary_key=True, comment='编号')
#     table_id = db.Column(db.String(255), comment='归属表编号')
#     db.Column_name = db.Column(db.String(255), comment='列名称')
#     db.Column_comment = db.Column(db.String(255), comment='列描述')
#     db.Column_type = db.Column(db.String(128), comment='列类型')
#     java_type = db.Column(db.String(255), comment='JAVA类型')
#     java_field = db.Column(db.String(255), comment='JAVA字段名')
#     is_pk = db.Column(db.CHAR(1), comment='是否主键（1是）')
#     is_increment = db.Column(db.CHAR(1), comment='是否自增（1是）')
#     is_required = db.Column(db.CHAR(1), comment='是否必填（1是）')
#     is_insert = db.Column(db.CHAR(1), comment='是否为插入字段（1是）')
#     is_edit = db.Column(db.CHAR(1), comment='是否编辑字段（1是）')
#     is_list = db.Column(db.CHAR(1), comment='是否列表字段（1是）')
#     is_query = db.Column(db.CHAR(1), comment='是否查询字段（1是）')
#     query_type = db.Column(db.String(255), comment='查询方式（等于、不等于、大于、小于、范围）')
#     html_type = db.Column(db.String(255), comment='显示类型（文本框、文本域、下拉框、复选框、单选框、日期控件）')
#     dict_type = db.Column(db.String(255), comment='字典类型')
#     sort = db.Column(db.Integer(), comment='排序')
#     create_by = db.Column(db.String(255), comment='创建者')
#     create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
#     update_by = db.Column(db.String(255), comment='更新者')
#     update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
# class SysJob(db.Model):
#     __tablename__ = 'sys_job'
#     __table_args__ = {'comment': '定时任务调度表'}
#
#     job_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='任务ID')
#     job_name = db.Column(db.String(255), primary_key=True, nullable=False, default="", comment='任务名称')
#     job_group = db.Column(db.String(255), primary_key=True, nullable=False, default="DEFAULT",
#                           comment='任务组名')
#     invoke_target = db.Column(db.String(255), nullable=False, comment='调用目标字符串')
#     cron_expression = db.Column(db.String(255), default="", comment='cron执行表达式')
#     misfire_policy = db.Column(db.String(255), default="3", comment='计划执行错误策略（1立即执行 2执行一次 3放弃执行）')
#     concurrent = db.Column(db.CHAR(1), default="1", comment='是否并发执行（0允许 1禁止）')
#     status = db.Column(db.CHAR(1), default="0", comment='状态（0正常 1暂停）')
#     create_by = db.Column(db.String(255), default="", comment='创建者')
#     create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
#     update_by = db.Column(db.String(255), default="", comment='更新者')
#     update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
#     remark = db.Column(db.String(255), default="", comment='备注信息')
#
#
# class SysJobLog(db.Model):
#     __tablename__ = 'sys_job_log'
#     __table_args__ = {'comment': '定时任务调度日志表'}
#
#     job_log_id = db.Column(db.Integer(), primary_key=True, comment='任务日志ID')
#     job_name = db.Column(db.String(255), nullable=False, comment='任务名称')
#     job_group = db.Column(db.String(255), nullable=False, comment='任务组名')
#     invoke_target = db.Column(db.String(255), nullable=False, comment='调用目标字符串')
#     job_message = db.Column(db.String(255), comment='日志信息')
#     status = db.Column(db.CHAR(1), default="0", comment='执行状态（0正常 1失败）')
#     exception_info = db.Column(db.String(255), default="", comment='异常信息')
#     create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')


class SysConfig(db.Model):
    __tablename__ = 'sys_config'
    __table_args__ = {'comment': '参数配置表'}

    config_id = db.Column(db.Integer(), primary_key=True, comment='参数主键')
    config_name = db.Column(db.String(128), default="", comment='参数名称')
    config_key = db.Column(db.String(128), default="", comment='参数键名')
    config_value = db.Column(db.String(255), default="", comment='参数键值')
    config_type = db.Column(db.CHAR(1), default="N", comment='系统内置（Y是 N否）')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), comment='备注')

    def to_dict(self):
        return {
            "config_id": self.config_id,
            "config_name": self.config_name,
            "config_key": self.config_key,
            "config_value": self.config_value,
            "config_type": self.config_type,
            "create_by": self.create_by,
            "update_by": self.update_by,
            "remark": self.remark,
            "create_time": date_func(self.create_time),
            "update_time": date_func(self.update_time)
        }


class SysDept(db.Model):
    __tablename__ = 'sys_dept'
    __table_args__ = {'comment': '部门表'}

    dept_id = db.Column(db.Integer(), primary_key=True, comment='部门id')
    parent_id = db.Column(db.Integer(), default="0", comment='父部门id')
    ancestors = db.Column(db.String(68), default="", comment='祖级列表')
    dept_name = db.Column(db.String(30), default="", comment='部门名称')
    order_num = db.Column(db.Integer(), default="0", comment='显示顺序')
    leader = db.Column(db.String(255), comment='负责人')
    phone = db.Column(db.String(11), comment='联系电话')
    email = db.Column(db.String(68), comment='邮箱')
    status = db.Column(db.CHAR(1), default="0", comment='部门状态（0正常 1停用）')
    del_flag = db.Column(db.CHAR(1), default="0", comment='删除标志（0代表存在 2代表删除）')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')

    def to_dict(self):
        return {
            "id": self.dept_id,
            "label": self.dept_name,
            "dept_id": self.dept_id,
            "parent_id": self.parent_id,
            "ancestors": self.ancestors,
            "dept_name": self.dept_name,
            "order_num": self.order_num,
            "leader": self.leader,
            "phone": self.phone,
            "email": self.email,
            "status": self.status,
            "del_flag": self.del_flag,
            "create_by": self.create_by,
            "update_by": self.update_by,
            "create_time": date_func(self.create_time),
            "update_time": date_func(self.update_time)
        }


class SysDictDatum(db.Model):
    __tablename__ = 'sys_dict_data'
    __table_args__ = {'comment': '字典数据表'}

    dict_code = db.Column(db.Integer(), primary_key=True, comment='字典编码')
    dict_sort = db.Column(db.Integer(), default="0", comment='字典排序')
    dict_label = db.Column(db.String(128), default="", comment='字典标签')
    dict_value = db.Column(db.String(128), default="", comment='字典键值')
    dict_type = db.Column(db.String(128), default="", comment='字典类型')
    css_class = db.Column(db.String(128), comment='样式属性（其他样式扩展）')
    list_class = db.Column(db.String(128), comment='表格回显样式')
    is_default = db.Column(db.CHAR(1), default="N", comment='是否默认（Y是 N否）')
    status = db.Column(db.CHAR(1), default="0", comment='状态（0正常 1停用）')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), comment='备注')

    def to_dict(self):
        return {
            "dict_code": self.dict_code,
            "dict_sort": self.dict_sort,
            "dict_label": self.dict_label,
            "dict_value": self.dict_value,
            "dict_type": self.dict_type,
            "css_class": self.css_class,
            "list_class": self.list_class,
            "is_default": self.is_default,
            "status": self.status,
            "create_by": self.create_by,
            "update_by": self.update_by,
            "remark": self.remark,

            "update_time": date_func(self.update_time),
            "create_time": date_func(self.create_time)
        }


class SysDictType(db.Model):
    __tablename__ = 'sys_dict_type'
    __table_args__ = {'comment': '字典类型表'}

    dict_id = db.Column(db.Integer(), primary_key=True, comment='字典主键')
    dict_name = db.Column(db.String(128), default="", comment='字典名称')
    dict_type = db.Column(db.String(128), unique=True, default="", comment='字典类型')
    status = db.Column(db.CHAR(1), default="0", comment='状态（0正常 1停用）')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), comment='备注')

    def to_dict(self):
        return {
            "dict_id": self.dict_id,
            "dict_name": self.dict_name,
            "dict_type": self.dict_type,
            "status": self.status,
            "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            "update_time": self.update_time.strftime("%Y-%m-%d %H:%M:%S"),
            "create_by": self.create_by,
            "update_by": self.update_by,
            "remark": self.remark,
        }


class SysLogininfor(db.Model):
    __tablename__ = 'sys_logininfor'
    __table_args__ = {'comment': '系统访问记录'}

    info_id = db.Column(db.Integer(), primary_key=True, comment='访问ID')
    user_name = db.Column(db.String(68), default="", comment='用户账号')
    ipaddr = db.Column(db.String(128), default="", comment='登录IP地址')
    login_location = db.Column(db.String(255), default="", comment='登录地点')
    browser = db.Column(db.String(68), default="", comment='浏览器类型')
    os = db.Column(db.String(68), default="", comment='操作系统')
    status = db.Column(db.CHAR(1), default="0", comment='登录状态（0成功 1失败）')
    msg = db.Column(db.String(255), default="", comment='提示消息')
    login_time = db.Column(db.DateTime, comment='访问时间')

    def to_dict(self):
        return {
            "info_id": self.info_id,
            "user_name": self.user_name,
            "ipaddr": self.ipaddr,
            "login_location": self.login_location,
            "browser": self.browser,
            "os": self.os,
            "status": self.status,
            "msg": self.msg,
            "login_time": self.login_time.strftime("%Y-%m-%d %H:%M:%S"),

        }
        pass


class SysMenu(db.Model):
    __tablename__ = 'sys_menu'
    __table_args__ = {'comment': '菜单权限表'}

    menu_id = db.Column(db.Integer(), primary_key=True, comment='菜单ID')
    menu_name = db.Column(db.String(68), nullable=False, comment='菜单名称')
    parent_id = db.Column(db.Integer(), default=0, comment='父菜单ID')
    order_num = db.Column(db.Integer(), default=0, comment='显示顺序')
    path = db.Column(db.String(255), default="", comment='路由地址')
    component = db.Column(db.String(255), comment='组件路径')
    is_frame = db.Column(db.CHAR(32), default="1", comment='是否为外链（0是 1否）')
    is_cache = db.Column(db.CHAR(32), default="0", comment='是否缓存（0缓存 1不缓存）')
    menu_type = db.Column(db.CHAR(1), default="", comment='菜单类型（M目录 C菜单 F按钮）')
    visible = db.Column(db.CHAR(1), default="0", comment='菜单状态（0显示 1隐藏）')
    status = db.Column(db.CHAR(1), default="0", comment='菜单状态（0正常 1停用）')
    perms = db.Column(db.String(128), comment='权限标识')
    icon = db.Column(db.String(128), default="#", comment='菜单图标')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), default="", comment='备注')

    def to_dict(self):
        return {
            "label": self.menu_name,
            "id": self.menu_id,
            "menu_id": self.menu_id,
            "menu_name": self.menu_name,
            "parent_id": self.parent_id,
            "order_num": self.order_num,
            "path": self.path,
            "component": self.component,
            "is_frame": self.is_frame,
            "is_cache": self.is_cache,
            "menu_type": self.menu_type,
            "visible": self.visible,
            "status": self.status,
            "perms": self.perms,
            "icon": self.icon,
            "create_by": self.create_by,
            "create_time": date_func(self.create_time),
            "update_by": self.update_by,
            "update_time": date_func(self.update_time),
            "remark": self.remark,
        }


class SysNotice(db.Model):
    __tablename__ = 'sys_notice'
    __table_args__ = {'comment': '通知公告表'}

    notice_id = db.Column(db.Integer(), primary_key=True, comment='公告ID')
    notice_title = db.Column(db.String(68), nullable=False, comment='公告标题')
    notice_type = db.Column(db.CHAR(1), nullable=False, comment='公告类型（1通知 2公告）')
    notice_content = db.Column(db.Text, comment='公告内容')
    status = db.Column(db.CHAR(1), default="0", comment='公告状态（0正常 1关闭）')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), comment='备注')

    def to_dict(self):
        return {
            "notice_id": self.notice_id,
            "notice_title": self.notice_title,
            "notice_type": self.notice_type,
            "notice_content": self.notice_content,
            "status": self.status,
            "create_by": self.create_by,
            "update_by": self.update_by,
            "remark": self.remark,
        }


class SysOperLog(db.Model):
    __tablename__ = 'sys_oper_log'
    __table_args__ = {'comment': '操作日志记录'}

    oper_id = db.Column(db.Integer(), primary_key=True, comment='日志主键')
    title = db.Column(db.String(68), default="", comment='模块标题')
    business_type = db.Column(db.Integer(), default="0", comment='业务类型（0其它 1新增 2修改 3删除）')
    method = db.Column(db.String(128), default="", comment='方法名称')
    request_method = db.Column(db.String(10), default="", comment='请求方式')
    operator_type = db.Column(db.Integer(), default="0", comment='操作类别（0其它 1后台用户 2手机端用户）')
    oper_name = db.Column(db.String(68), default="", comment='操作人员')
    dept_name = db.Column(db.String(68), default="", comment='部门名称')
    oper_url = db.Column(db.String(255), default="", comment='请求URL')
    oper_ip = db.Column(db.String(128), default="", comment='主机地址')
    oper_location = db.Column(db.String(255), default="", comment='操作地点')
    oper_param = db.Column(db.String(255), default="", comment='请求参数')
    json_result = db.Column(db.String(255), default="", comment='返回参数')
    status = db.Column(db.Integer(), default="0", comment='操作状态（0正常 1异常）')
    error_msg = db.Column(db.String(255), default="", comment='错误消息')
    oper_time = db.Column(db.DateTime, comment='操作时间')

    def to_dict(self):
        return {
            "oper_time": self.oper_time.strftime("%Y-%m-%d %H:%M:%S"),
            # "update_time": self.update_time.strftime("%Y-%m-%d %H:%M:%S"),

            "oper_id": self.oper_id,
            "title": self.title,
            "business_type": self.business_type,
            "method": self.method,
            "request_method": self.request_method,
            "operator_type": self.operator_type,
            "oper_name": self.oper_name,
            "oper_url": self.oper_url,
            "oper_ip": self.oper_ip,
            "oper_location": self.oper_location,
            "oper_param": self.oper_param,
            "json_result": self.json_result,
            "status": self.status,
            "error_msg": self.error_msg,
            # "oper_time": self.oper_time,
        }


class SysPost(db.Model):
    __tablename__ = 'sys_post'
    __table_args__ = {'comment': '岗位信息表'}

    post_id = db.Column(db.Integer(), primary_key=True, comment='岗位ID')
    post_code = db.Column(db.String(255), nullable=False, comment='岗位编码')
    post_name = db.Column(db.String(68), nullable=False, comment='岗位名称')
    post_sort = db.Column(db.Integer(), nullable=False, comment='显示顺序')
    status = db.Column(db.CHAR(1), nullable=False, comment='状态（0正常 1停用）')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), comment='备注')

    def to_dict(self):
        return {
            "post_id": self.post_id,
            "post_code": self.post_code,
            "post_name": self.post_name,
            "post_sort": self.post_sort,
            "status": self.status,
            "create_by": self.create_by,
            "update_by": self.update_by,
            "remark": self.remark,
            "create_time": date_func(self.create_time),
            "update_time": date_func(self.update_time)
        }


class SysRole(db.Model):
    __tablename__ = 'sys_role'
    __table_args__ = {'comment': '角色信息表'}

    role_id = db.Column(db.Integer(), primary_key=True, comment='角色ID')
    role_name = db.Column(db.String(30), nullable=False, comment='角色名称')
    role_key = db.Column(db.String(128), nullable=False, comment='角色权限字符串')
    role_sort = db.Column(db.Integer(), nullable=False, comment='显示顺序')
    data_scope = db.Column(db.CHAR(1), default="1", comment='数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 8：本部门及以下数据权限）')
    menu_check_strictly = db.Column(db.Integer(), default=1, comment='菜单树选择项是否关联显示')
    dept_check_strictly = db.Column(db.Integer(), default=1, comment='部门树选择项是否关联显示')
    status = db.Column(db.CHAR(1), nullable=False, default='0', comment='角色状态（0正常 1停用）')
    del_flag = db.Column(db.CHAR(1), default="0", comment='删除标志（0代表存在 2代表删除）')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), comment='备注')

    def to_dict(self):
        return {
            "role_id": self.role_id,
            "role_name": self.role_name,
            "role_key": self.role_key,
            "role_sort": self.role_sort,
            "data_scope": self.data_scope,
            "menu_check_strictly": True if self.menu_check_strictly == 1 else False,
            "dept_check_strictly": True if self.dept_check_strictly == 1 else False,
            "status": self.status,
            "del_flag": self.del_flag,
            "create_by": self.create_by,
            "update_by": self.update_by,
            "remark": self.remark,
            "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            "update_time": self.update_time.strftime("%Y-%m-%d %H:%M:%S"),
        }


class SysRoleDept(db.Model):
    __tablename__ = 'sys_role_dept'
    __table_args__ = {'comment': '角色和部门关联表'}

    role_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='角色ID')
    dept_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='部门ID')

    def to_dict(self):
        return {
            "role_id": self.role_id,
            "dept_id": self.dept_id
        }


class SysRoleMenu(db.Model):
    __tablename__ = 'sys_role_menu'
    __table_args__ = {'comment': '角色和菜单关联表'}

    role_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='角色ID')
    menu_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='菜单ID')

    def to_dict(self):
        return {
            "role_id": self.role_id,
            "menu_id": self.menu_id
        }


class SysUser(db.Model):
    __tablename__ = 'sys_user'
    __table_args__ = {'comment': '用户信息表'}

    user_id = db.Column(db.Integer(), primary_key=True, comment='用户ID')
    dept_id = db.Column(db.Integer(), comment='部门ID')
    user_name = db.Column(db.String(30), nullable=False, comment='用户账号')
    nick_name = db.Column(db.String(30), nullable=False, comment='用户昵称')
    user_type = db.Column(db.String(2), default="00", comment='用户类型（00系统用户）')
    email = db.Column(db.String(68), default="", comment='用户邮箱')
    phonenumber = db.Column(db.String(11), default="", comment='手机号码')
    sex = db.Column(db.CHAR(1), default="0", comment='用户性别（0男 1女 2未知）')
    avatar = db.Column(db.String(128), default="", comment='头像地址')
    password = db.Column(db.String(128), default="", comment='密码')
    status = db.Column(db.CHAR(1), default="0", comment='帐号状态（0正常 1停用）')
    del_flag = db.Column(db.CHAR(1), default="0", comment='删除标志（0代表存在 2代表删除）')
    login_ip = db.Column(db.String(128), default="", comment='最后登录IP')
    login_date = db.Column(db.DateTime, default=datetime.now(), comment='最后登录时间')
    create_by = db.Column(db.String(255), default="", comment='创建者')
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_by = db.Column(db.String(255), default="", comment='更新者')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')
    remark = db.Column(db.String(255), comment='备注')

    def get_password(self):
        return {
            "user_id": self.user_id,
            "password": self.password,
            "user_name": self.user_name,
        }

    def to_dict(self):
        return {
            "user_id": self.user_id,
            "dept_id": self.dept_id,
            "user_name": self.user_name,
            "nick_name": self.nick_name,
            "user_type": self.user_type,
            "email": self.email,
            "phonenumber": self.phonenumber,
            "sex": self.sex,
            "avatar": self.avatar,
            "status": self.status,
            "del_flag": self.del_flag,
            "login_ip": self.login_ip,
            "login_date": self.login_date.strftime("%Y-%m-%d %H:%M:%S"),
            "create_by": self.create_by,
            "update_by": self.update_by,
            "remark": self.remark,
            "create_time": self.create_time.strftime("%Y-%m-%d %H:%M:%S"),
        }


class SysUserPost(db.Model):
    __tablename__ = 'sys_user_post'
    __table_args__ = {'comment': '用户与岗位关联表'}

    user_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='用户ID')
    post_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='岗位ID')

    def to_dict(self):
        return {
            "user_id": self.user_id,
            "post_id": self.post_id,
        }


class SysUserRole(db.Model):
    __tablename__ = 'sys_user_role'
    __table_args__ = {'comment': '用户和角色关联表'}

    user_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='用户ID')
    role_id = db.Column(db.Integer(), primary_key=True, nullable=False, comment='角色ID')

    def to_dict(self):
        return {
            "user_id": self.user_id,
            "role_id": self.role_id,
        }
